/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Formas;

import java.awt.Graphics;
import java.awt.Graphics2D;

/**
 *
 * @author Pedro
 */
public class Retangulo extends Forma{
    private int width;
    private int height;

    public Retangulo(int sX, int sY, int width, int height)
    {
       super(sX,sY);
       this.width = width;
       this.height = height;
       xCentro = sX + (width / 2);
       yCentro = sY + (height / 2);
    }

    @Override
    public Forma drawForma(Graphics g)
    {  
        g.setColor(this.getCor());
        g.drawRect(super.getsX(),super.getsY(), width, height);       
        return this;
    }

    @Override
    public boolean pertenceAForma(int x,int y) {
        int raio = this.getWidth() / 2;
        int sX = this.getWidth() / 2,sY = this.getHeight() / 2;
        return (Math.pow(x - xCentro, 2) + Math.pow(y - yCentro, 2)) < Math.pow(this.getWidth() / 2,2);
    }

    /**
     * @return the width
     */
    public int getWidth() {
        return width;
    }

    /**
     * @param width the width to set
     */
    public void setWidth(int width) {
        this.width = width;
       xCentro = this.getsX() + (width / 2);
       yCentro = this.getsY() + (height / 2);
    }

    /**
     * @return the height
     */
    public int getHeight() {
       return height;

    }

    /**
     * @param height the height to set
     */
    public void setHeight(int height) {
        this.height = height;
        xCentro = this.getsX() + (width / 2);
        yCentro = this.getsY() + (height / 2);
    }

    @Override
    public void setsX(int sX) {
        super.setsX(sX);
       xCentro = sX + (width / 2);
       yCentro = this.getsY() + (height / 2);
    }

    @Override
    public void setsY(int sY) {
        super.setsY(sY);
       xCentro = super.getsX() + (width / 2);
       yCentro = super.getsY() + (height / 2);
    }

}
